package org.dinnermate.log;

/**
 * This class, and classes it uses, are almost direct copies of the ones from "java.util.logging"
 * but a little more tailored to our project. We may just end up using the ones built into java as
 * "net.java.ao" already uses them.
 * 
 * @author jeff
 * 
 */
public class Logger
{
	private Handler handler;

	protected Logger()
	{}

	public Handler getHandler()
	{
		return handler;
	}

	public void setHandler( Handler handler )
	{
		this.handler = handler;
	}

	public void log( LogRecord record )
	{
		handler.publish(record);
	}

	public void log( Level level, String msg )
	{
		log(new LogRecord(level, msg));
	}

	public void log( Level level, String msg, Throwable thrown )
	{
		LogRecord lr = new LogRecord(level, msg);
		lr.setThrown(thrown);
		log(lr);
	}

	public void log( Level level, String sourceClass, String sourceMethod, String msg )
	{
		LogRecord lr = new LogRecord(level, msg);
		lr.setSourceClassName(sourceClass);
		lr.setSourceMethodName(sourceMethod);
		log(lr);
	}

	public void log( Level level, String sourceClass, String sourceMethod, String msg,
			Throwable thrown )
	{
		LogRecord lr = new LogRecord(level, msg);
		lr.setSourceClassName(sourceClass);
		lr.setSourceMethodName(sourceMethod);
		lr.setThrown(thrown);
		log(lr);
	}

	public void info( String msg )
	{
		log(Level.INFO, msg);
	}

	public void warning( String msg )
	{
		log(Level.WARNING, msg);
	}

	public void fine( String msg )
	{
		log(Level.FINE, msg);
	}

	public void throwing( String sourceClass, String sourceMethod, Throwable thrown )
	{
		log(Level.FINE, sourceClass, sourceMethod, "THROWN", thrown);
	}

	public void severe( String msg )
	{
		log(Level.SEVERE, msg);
	}

	public void severe( String msg, Throwable cause )
	{
		log(Level.SEVERE, msg, cause);
	}

	/*
	 * SINGLETON CLASS AND METHOD
	 */

	private static class SingletonHolder
	{
		private final static Logger INSTANCE = new Logger();
	}

	public static Logger getInstance()
	{
		return SingletonHolder.INSTANCE;
	}
}
